import { useUserStore } from "@/stores/user"


export function useAuth() {
  const userStore = useUserStore()

  // 检查是否需要登录，但不强制跳转
  const isLoggedIn = () => {
    return userStore.checkLoginStatus()
  }

  // 检查是否需要登录并跳转
  const checkNeedLogin = (shouldRedirect: boolean = false) => {
    if (!userStore.checkLoginStatus()) {
      if (shouldRedirect) {
        uni.navigateTo({
          url: '/pages/login/login'
        })
      }
      return true
    }
    return false
  }

  // 检查是否已登录并绑定手机号
  const isUserLoggedInAndBoundPhone = () => {
    const userInfo = userStore.userInfo
    return !!userInfo?.access_token && !!userInfo?.phone
  }

  return {
    checkNeedLogin,
    isLoggedIn,
    isUserLoggedInAndBoundPhone
  }
} 